/*
db.order.aggregate([
    {
		$lookup:
    	{
        	from: "order_item",
          	localField: "order_id",
          	foreignField: "order_id",
          	as: "items"
        }
   	}, {
		$match:{"all_price":{$gte:90}}
	}
])
*/
const ArticleModel = require("./model/article");

// 查询文章信息
/* ArticleModel.find({}, function(err, data) {
	console.log(`data`, data);
}) */

// 查询文章信息并显示文章的分类以及文章的作者信息
// 两个表关联
/* ArticleModel.aggregate([
	{
		$lookup: {
			from: "articlecate",
			localField: "cid",
			foreignField: "_id",
			as: "cate"
		}
	}
], function(err, docs) {
	if(err) {
		console.log(err);
		return
	}
	console.log(JSON.stringify(docs));
}) */

// 三个表关联查询
ArticleModel.aggregate([
	{
		$lookup: {
			from: "articlecate",
			localField: "cid",
			foreignField: "_id",
			as: "cate"
		}
	},
	{
		$lookup: {
			from: "user",
			localField: "author_id",
			foreignField: "_id",
			as: "author"
		}
	}
], function(err, docs) {
	if(err) {
		console.log(err);
		return
	}
	console.log(JSON.stringify(docs));
})